# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=python-pytest-django
pkgver=4.5.2
_commit=27d65607d82f6915bbc56f73779eab013f596708
pkgrel=4
pkgdesc="A Django plugin for py.test"
arch=('any')
license=('BSD')
url="https://github.com/pytest-dev/pytest-django"
depends=('python-pytest')
makedepends=('git' 'python-setuptools-scm')
checkdepends=('python-django' 'python-pytest-xdist')
source=("git+https://github.com/pytest-dev/pytest-django.git#commit=$_commit")
sha512sums=('SKIP')

prepare() {
  cd pytest-django
  # pytest 7
  git cherry-pick -n 14b993d1cb291bfcf05f35f57db55c0419886534
}

build() {
  cd pytest-django
  python setup.py build
}

check() {
  # Hack entry points by installing it

  cd pytest-django
  python setup.py install --root="$PWD/tmp_install" --optimize=1
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  PYTHONPATH="$PWD/tmp_install/$site_packages:$PYTHONPATH:$PWD" \
  DJANGO_SETTINGS_MODULE=pytest_django_test.settings_sqlite \
    py.test tests
}

package() {
  cd pytest-django
  python setup.py install --root="$pkgdir" --optimize=1
  install -Dm664 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}
